package com.apes.fn.scm.crossCompany.transfer.model;

import com.apes.framework.jpa.DefaultPersistListener;
import com.apes.framework.jpa.Model;
import com.apes.framework.jpa.comment.Comment;
import com.apes.framework.jpa.generator.ApesGenerator;
import com.apes.framework.util.ApesConst;
import com.apes.scm.account.account.model.InventoryBatch;
import com.apes.scm.masterdata.product.model.Product;
import com.apes.scm.masterdata.product.model.ProductUom;
import lombok.Getter;
import lombok.Setter;
import org.hibernate.annotations.DynamicInsert;
import org.hibernate.annotations.DynamicUpdate;
import org.hibernate.annotations.SelectBeforeUpdate;

import javax.persistence.*;
import javax.validation.constraints.NotNull;

/**
 * @BelongsProject: apes-server
 * @BelongsPackage: com.apes.fn.scm.crossCompany.transfer.model
 * @Author: ljp
 * @CreateTime: 2021-06-11 15:09
 * @Description: 批次调拨表
 */
@Getter
@Setter
@SelectBeforeUpdate
@DynamicInsert
@DynamicUpdate
@Entity
@EntityListeners(DefaultPersistListener.class)
@Table(name = TransferBatch.CONST_TABLE_NAME)
public class TransferBatch extends Model {
    public static final String CONST_TABLE_NAME = "cross_transfer_batch";

    @Id
    @Column(name = "id",nullable = false,length = 64)
    @Comment("编码")
    @ApesGenerator(code = CONST_TABLE_NAME, name = "批次调拨表", padding = 8)
    private String id;

    @OneToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "transfer_item_id", referencedColumnName = "id")
    @Comment("调拨明细")
    private CrossCompanyTransferItemNew companyTransferItem;

    @NotNull
    @ManyToOne(optional = false)
    @JoinColumn(name = "transfer_id", referencedColumnName = "id")
    @Comment("调拨单号")
    private CrossCompanyTransferNew crossCompanyTransfer;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_id", referencedColumnName = "id")
    @Comment("商品")
    private Product product;

    @NotNull
    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "product_uom_id", referencedColumnName = "id")
    @Comment("计量单位")
    private ProductUom uom;

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "batch_code", referencedColumnName = "id")
    @Comment("商品批次内码")
    private InventoryBatch inventoryBatch;

    @Column(name = "product_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("调拨数量")
    private double productQty = 0;

    @Column(name = "ship_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("发货数量")
    private double ShipQty = 0;//用于调拨终止

    @Column(name = "voucher_qty", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("凭证数量")
    private double voucherQty = 0;//用于创建凭证凭证

    @Column(name = "finish_sum", nullable = false, columnDefinition = ApesConst.FIELD_QTY_16_4_0)
    @Comment("终止数量")
    private double finishSum = 0;
}
